package com.senac.servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import com.senac.model.Usuario;
import com.senac.service.GerenciamentoEscolaService;
import com.senac.service.UsuarioService;

@WebServlet("/usuario")
public class CrudUsuarioServlet extends GerenciamentoEscolaAvancado<Usuario> {

	private static final long serialVersionUID = -2302968858853427368L;

	@Override
	protected String getPageView() {
		return "pages/usuarioView.jsp";
	}
	
	@Override
	protected String getPageList() {
		return "pages/usuarioListar.jsp";
	}
	
	@Override
	protected String getUrlListagem() {
		return "listarUsuarios";
	}
	
	@Override
	protected String getUrlCadastro() {
		return "usuario";
	}
	
	@Override
	protected String getListAttributeName() {
		return "usuarios";
	}
	
	@Override
	protected String getViewAttributeName() {
		return "user";
	}
	
	@Override
	protected GerenciamentoEscolaService<Usuario> getService() {
		return new UsuarioService();
	}	
		
	protected Usuario mountByRequest(HttpServletRequest req) {
		Usuario user = new Usuario();
		String idString = req.getParameter("id");
		if(idString != null && !idString.equals("")) {
			user.setId(Integer.parseInt(idString));
		}		
		user.setNome(req.getParameter("nome"));
		user.setLogin(req.getParameter("login"));
		user.setSenha(req.getParameter("senha"));
		user.setEmail(req.getParameter("email"));
		return user;
	}

}
